/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * stuChooseDialog.java
 *
 * Created on 2011-5-10, 23:16:29
 */
package junchangmis.student;

import junchangmis.*;
import publicmethod.*;
import javax.swing.JOptionPane;
import java.util.Vector;

/**
 *
 * @author developers
 */
public class stuChooseDialog extends javax.swing.JDialog {

    MainFrame parent;

    /** Creates new form stuChooseDialog */
    public stuChooseDialog(java.awt.Frame parent, boolean modal, MainFrame pparent) {
        super(parent, modal);
        this.parent = pparent;
        initComponents();
        this.setTitle("信息查询与修改");
        this.setLocationRelativeTo(null);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabelChoose = new javax.swing.JLabel();
        jComboBoxChoose = new javax.swing.JComboBox();
        jLabelCondition = new javax.swing.JLabel();
        jTextFieldCondition = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jButtonOK = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabelChoose.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabelChoose.setText("请选择查询种类");

        jComboBoxChoose.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxChoose.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "按学生编码查询", "按学生姓名查询" }));

        jLabelCondition.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jLabelCondition.setText("请输入查询内容");

        jTextFieldCondition.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelCondition)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCondition))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelChoose)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxChoose, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(47, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelChoose)
                    .addComponent(jComboBoxChoose, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCondition)
                    .addComponent(jTextFieldCondition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jButtonOK.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jButtonOK.setText("确定");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(212, 212, 212)
                .addComponent(jButtonOK)
                .addContainerGap(217, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonOK)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        // TODO add your handling code here:
        if (this.jComboBoxChoose.getSelectedIndex() == 0) {//按学生编码查询
            formalStu student = new formalStu();
            boolean flag = stuChooseMethod.hasFormalStu(this.jTextFieldCondition.getText(), student);
            if (flag == false) {
                JOptionPane.showConfirmDialog(null, "不存在该编码的学生！", "提示", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE);
                return;
            } else {
                formalStuInputUI fr = new formalStuInputUI(this.parent, true, this.parent, student);
                dispose(); //关闭自己
                fr.setVisible(true);//打开查询窗口

            }
        } else {//按姓名查询 列出该名学生的所有记录 可能为多专业学生 也可能为重名的学生
            Vector<formalStu> stuName = new Vector<formalStu>();
            boolean flag = stuChooseMethod.hasFormalStuAsName(this.jTextFieldCondition.getText(), stuName);
            if (flag == false) {
                JOptionPane.showConfirmDialog(null, "不存在该姓名的学生！", "提示", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE);
                return;
            } else {
                if (stuName.size() == 1) {//仅一个记录
                    formalStuInputUI fr = new formalStuInputUI(this.parent, true, this.parent, stuName.get(0));
                    dispose(); //关闭自己
                    fr.setVisible(true);//打开查询窗口
                } else {//多个记录
                    itemsDialog fr = new itemsDialog(this.parent, true, this.parent, stuName);
                    dispose();
                    fr.setVisible(true);

                }
            }
        }
    }//GEN-LAST:event_jButtonOKActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
        stuChooseDialog dialog = new stuChooseDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) {
        System.exit(0);
        }
        });
        dialog.setVisible(true);
        }
        });*/
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonOK;
    private javax.swing.JComboBox jComboBoxChoose;
    private javax.swing.JLabel jLabelChoose;
    private javax.swing.JLabel jLabelCondition;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextFieldCondition;
    // End of variables declaration//GEN-END:variables
}
